#AutoIt3Wrapper_Version=beta
#AutoIt3Wrapper_Res_Description=Simplifies the management of your installer EXEs.
#AutoIt3Wrapper_Res_Fileversion=0.0.1.0
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d
#AutoIt3Wrapper_Run_After=md "%scriptdir%\Versions\%fileversion%"
#AutoIt3Wrapper_Run_After=copy "%in%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.au3"
#AutoIt3Wrapper_Run_After=copy "%out%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.exe"
#AutoIt3Wrapper_Run_Obfuscator=y

Switch @CPUArch
	Case "X86"
		#AutoIt3Wrapper_UseX64=n
	Case "X64"
		#AutoIt3Wrapper_UseX64=y
EndSwitch

#region Organize Includes
#include <File.au3>
#include <Misc.au3>
#endregion Organize Includes

_Singleton(@ScriptName)

HotKeySet("{ESC}", "terminate")
OnAutoItExitRegister("_EXIT")

FormatTextFile(@ScriptDir & "\List Of IM Colors.txt", ' ')
ConsoleWrite("List of IM Colors " & @error & @LF)

;~ FormatTextFile(@ScriptDir & "\List Of Image Properties.txt", ':')
;~ ConsoleWrite("List of Image Properties " & @error & @LF)

Func FormatTextFile(Const $FileName, Const $BeginStr, Const $CaseSense = 0, Const $Occurence = 1)
	Local $szDrive, $szDir, $szFName, $szExt
	_PathSplit($FileName, $szDrive, $szDir, $szFName, $szExt)

	Local Const $ShiningPath = $szDrive & $szDir & $szFName

	; create a backup -- just in case
	Local Const $BACKUP_SUCCESS = FileCopy($FileName, $ShiningPath & ".BAK", 1 + 8)

	Switch $BACKUP_SUCCESS
		Case 1
			ConsoleWrite("Backup Success" & @LF)
			Local Const $ColorListFile = FileOpen($FileName)

			If $ColorListFile = -1 Then
				Return SetError(-3, 0, 1)
			EndIf

			Local Const $FileNameNEW = $ShiningPath & " NEW.txt"
			Local Const $NewFile = FileOpen($FileNameNEW, 2)

			If $NewFile = -1 Then Return SetError(-2, 0, 1)

			Local $Line, $Count, $NewLine, $TrimCount, $Flag = 0, $error = 0

			While $error = 0
				$Line = FileReadLine($ColorListFile)
				$error = @error

				$Count = StringInStr($Line, $BeginStr, $CaseSense, $Occurence)
				ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Count = ' & $Count & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

				If $Count Then
					$Flag = 1
					$TrimCount = StringLen($Line) - ($Count - 1)
					$NewLine = StringLower(StringStripWS(StringTrimRight($Line, $TrimCount), 8))
					;;$NewLine = StringReplace($NewLine, $BeginStr, '')
					FileWriteLine($NewFile, $NewLine)
				EndIf
			WEnd

			FileClose($ColorListFile)
			FileClose($NewFile)

			Switch $Flag
				Case 1
					FileDelete($FileName)
					FileMove($FileNameNEW, $FileName)
					Return SetExtended(1)
				Case 0
					Return SetExtended(2)
			EndSwitch
		Case 0
			Return SetError(-1, 0, 1)
	EndSwitch
EndFunc   ;==>FormatTextFile

Func terminate()
	Exit
EndFunc   ;==>terminate

Func _exit()
	OnAutoItExitUnregister("_EXIT")
EndFunc   ;==>_exit